var spuAsinChart = {
    /**
     * 描述 : 初始化图表
     * 作者 : Y.X.chen
     */
    _init: function () {
        var data = JSON.parse($("#chart").val());
        var option = {
            title: {
                text: data.title
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    // type: 'cross',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            legend: {
                //标题
                data: data.legendData
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    //横坐标 时间
                    data: data.xAxis,
                    name: '日期',
                    axisLabel: {
                        formatter: function (value, index) {
                            return value + data.operateInfo[index];
                        },
                        textStyle: {
                            // color: 'green',
                            fontSize: 14,
                            lineHeight: 300,
                            
                        },
                    },
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: data.series
        };

        $("#workingMain").remove();
        $('#table-responsive').append('<div id="workingMain" style="width: 100%;height: 500px;" ></div>');
        echarts.init(document.getElementById('workingMain')).setOption(option);
    },
    /**
     * 描述 : 时间变更触发
     * 作者 : Y.X.chen
     */
    'changeTimeS': function(timeS) {
        if (timeS == $("#oldTimeS").val()) {
            return false;
        }

        var timeE = $("#oldTimeE").val();
        var searchStr = "&id=";
        searchStr += $("#flag").val();

        $.ajax({
            url: ROOT_URL + '/?c=ctrl_wish_wishProduct&a=productChart&timeS=' + timeS + "&timeE=" + timeE + searchStr,
            type: 'POST',
            dataType: 'json',
            success: function (result) {
                if (result.hasOwnProperty("code") && result.code === 200) {
                    $("#oldTimeS").val(timeS);
                    $("#chart").val(result.data);
                    spuAsinChart._init();
                    return false;
                } else {
                    layer.msg(result.info, {icon: 2, time: 800});
                    return false;
                }
            }
        });
    },
    /**
     * 描述 : 时间变更触发
     * 作者 : Y.X.chen
     */
    'changeTimeE': function(timeE) {
        if (timeE == $("#oldTimeE").val()) {
            return false;
        }

        var timeS = $("#oldTimeS").val();
        var searchStr = "&id=";
        searchStr += $("#flag").val();

        $.ajax({
            url:  ROOT_URL + '/?c=ctrl_wish_wishProduct&a=productChart&timeS=' + timeS + "&timeE=" + timeE + searchStr,
            type: 'POST',
            dataType: 'json',
            success: function (result) {
                if (result.hasOwnProperty("code") && result.code === 200) {
                    $("#oldTimeE").val(timeE);
                    $("#chart").val(result.data);
                    spuAsinChart._init();
                    return false;
                } else {
                    layer.msg(result.info, {icon: 2, time: 800});
                    return false;
                }
            }
        });
    },

};

$(function () {
    spuAsinChart._init();
});

$(".logTitle").click(function() {
    if ($(".logInfo").css('display') == 'none') {
        $("#iconLog").removeClass("layui-icon-right");
        $("#iconLog").addClass("layui-icon-down");
        $(".logInfo").slideDown(1000);
    } else {
        $("#iconLog").removeClass("layui-icon-down");
        $("#iconLog").addClass("layui-icon-right");
        $(".logInfo").slideUp(1000);
    }
})